{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "602a13e7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:15:28.793531Z",
     "start_time": "2022-07-08T18:15:27.719700Z"
    }
   },
   "outputs": [],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官网获取的AK】&client_secret=【官网获取的SK】'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7574b7e6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:17:39.913100Z",
     "start_time": "2022-07-08T18:17:39.770819Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.119c08749b9c2130c3a9bc68c9267c93.315360000.1972664258.282335-25904854', 'expires_in': 2592000, 'session_key': '9mzdC35AZ2XigcSeSUTsk5ERUQayO+JJyTFAoJ1QBVlh2R4pe9peXaHehc2PXH6eGWSrJq5aOLg6l2lv7fmlM2SomiYyLA==', 'access_token': '24.0f4372156564f5dbb11031dbb0664b8b.2592000.1659896258.282335-25904854', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': 'ad73b52cb897ae9ef896af233e1887da'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'i2aZ1sl4b2KDzTGUplQvGeDs',\n",
    "    'client_secret':'e5Z5fB3rTh4Xm71zSdOyquMYniKA4Qej'\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7f32f78f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:18:11.611534Z",
     "start_time": "2022-07-08T18:18:11.570643Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.0f4372156564f5dbb11031dbb0664b8b.2592000.1659896258.282335-25904854'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "access_token = response.json()['access_token']\n",
    "access_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "72f66956",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:18:26.270501Z",
     "start_time": "2022-07-08T18:18:26.254544Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.119c08749b9c2130c3a9bc68c9267c93.315360000.1972664258.282335-25904854',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdC35AZ2XigcSeSUTsk5ERUQayO+JJyTFAoJ1QBVlh2R4pe9peXaHehc2PXH6eGWSrJq5aOLg6l2lv7fmlM2SomiYyLA==',\n",
       " 'access_token': '24.0f4372156564f5dbb11031dbb0664b8b.2592000.1659896258.282335-25904854',\n",
       " 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx',\n",
       " 'session_secret': 'ad73b52cb897ae9ef896af233e1887da'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dfe883c7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:19:12.319686Z",
     "start_time": "2022-07-08T18:19:12.298742Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.0f4372156564f5dbb11031dbb0664b8b.2592000.1659896258.282335-25904854'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wingyi_API = response.json()['access_token']\n",
    "wingyi_API "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "524335e9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-07-08T18:23:34.693810Z",
     "start_time": "2022-07-08T18:23:27.698390Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'location_result': {'top': 694, 'left': 358, 'width': 2491, 'height': 998}, 'color_result': '黑色', 'result': [{'year': '2004-2015', 'name': '布加迪威航', 'score': 0.9586535692214966}, {'year': '2018', 'name': '布加迪Chiron', 'score': 0.002492609899491072}, {'year': '2019', 'name': 'GumpertApollo', 'score': 0.001220861333422363}, {'year': '2013', 'name': '雪铁龙Survolt', 'score': 0.001101878238841891}, {'year': '2009', 'name': '布加迪Galibier', 'score': 0.001020416151732206}], 'log_id': 1545473676968282915}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "车型识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/car\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('47.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,\"top_num\":5}\n",
    "access_token = access_token\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "raw",
   "id": "865c8e5f",
   "metadata": {},
   "source": [
    "{'location_result': {'top': 694, 'left': 358, 'width': 2491, 'height': 998}, \n",
    "'color_result': '黑色', 'result': [{'year': '2004-2015', 'name': '布加迪威航', 'score': 0.9586535692214966}, {'year': '2018', 'name': '布加迪Chiron', 'score': 0.002492609899491072}, {'year': '2019', 'name': 'GumpertApollo', 'score': 0.001220861333422363}, {'year': '2013', 'name': '雪铁龙Survolt', 'score': 0.001101878238841891}, {'year': '2009', 'name': '布加迪Galibier', 'score': 0.001020416151732206}], 'log_id': 1545473676968282915}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d97d0db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "187b3163",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
